/**************************************************************
 *@ProjectName: blweibo
 *@FileName: CustomException.java
 *@Date: 2011-5-30
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo.util;

import java.lang.Thread.UncaughtExceptionHandler;

import android.content.Context;

/**
 * The Class CustomException.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-30
 */
public class CustomException implements UncaughtExceptionHandler {

    /** The m context. */
    // private Context mContext;

    /** The default exception handler. */
    private Thread.UncaughtExceptionHandler defaultExceptionHandler;

    /** The custom exception. */
    private static CustomException customException;

    /**
     * Instantiates a new custom exception.
     */
    private CustomException() {
    }

    /**
     * Gets the single instance of CustomException.
     * 
     * @return single instance of CustomException
     */
    public static CustomException getInstance() {
        if (customException == null) {
            customException = new CustomException();
        }
        return customException;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang
     * .Thread, java.lang.Throwable)
     */
    @Override
    public void uncaughtException(Thread thread, Throwable exception) {
        if (defaultExceptionHandler != null) {
            Logger.d(exception);
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
            // defaultExceptionHandler.uncaughtException(thread, exception);
        }
    }

    /**
     * Inits the.
     * 
     * @param context
     *            the context
     */
    public void init(Context context) {
        // mContext = context;
        defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    }
}